package org.example.casLoginDemo.config;


import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Configguaration implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        return true;
       /* Result res = new Result();
        //反射获取自定义注解
        HandlerMethod hm = (HandlerMethod) handler;
        LoginValidate loginValidate = hm.getMethod().getAnnotation(LoginValidate.class);
        if(loginValidate != null){
            String  value = loginValidate.value();
            res.setReturn(response,0,value);
            return  false;
        }



        Map<String,Object> map = new HashMap<>();
        String token = request.getHeader("token");

        try {
            System.out.println(token);
            JWTUtils.verify(token);
            return true;
        }catch (ExpiredJwtException e){
            e.printStackTrace();
            res.fail("token已过期");
        }catch (MalformedJwtException e){
            e.printStackTrace();
            res.fail(" 密钥验证不一致");
        }catch (SignatureException e){
            e.printStackTrace();
            res.fail("签名异常");
        }catch (Exception e){
            e.printStackTrace();
            res.fail("认证失败");
        }
        String json = JSONObject.toJSONString(res);
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(json);
        return  false; */
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }





}
